/*
Copyright (C) 2022-2024 Inspur Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/
package sessionmgr

import (
	"net/http"
)

var sessMgrPlugin *SessionMgrPlugin

type SessionMgrInterface interface {
	Check(userId string, req *http.Request) bool
	Add(userId string, token string, req *http.Request)
	Remove(userId string)
}

// Mgr 会话管理器接口
type SessionMgrPlugin struct {
	impl SessionMgrInterface
}

// 初始化认证插件
func Init() *SessionMgrPlugin {
	sessMgrPlugin = new(SessionMgrPlugin)

	sessMgrPlugin.impl = NewMemoryMgr()
	return sessMgrPlugin
}

func Get() *SessionMgrPlugin {
	return sessMgrPlugin
}

func (ap *SessionMgrPlugin) Check(userId string, req *http.Request) bool {
	return ap.impl.Check(userId, req)
}
func (ap *SessionMgrPlugin) Add(userId string, token string, req *http.Request) {
	ap.impl.Add(userId, token, req)
}
func (ap *SessionMgrPlugin) Remove(userId string) {
	ap.impl.Remove(userId)
}
